<template>
  <div>
    <div class="herdertop">
      <img src="../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>商圈管理</el-breadcrumb-item>
        <el-breadcrumb-item>查看商圈</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="height: 100%;">
      <!--  -->
      <!-- :name="areaName" :path="pathArea" -->
      <maparea @update="update"></maparea>
      <ul>
        <li v-for="(item, index) in data" :key="index">
          {{ item.questionName }}
        </li>
      </ul>
    </div>
  </div>
</template>
<style scoped></style>
<script>
import maparea from "./map-area.vue";
import Bus from "../api/bus";

export default {
  inject: ["reload"],
  data() {
    return {
      isCollapse: "",
      location: [],
      data: []
    };
  },
  components: {
    maparea
  },
  created() {},
  methods: {
    update(arr, center, area, cityCode, cityName, lting) {
      let _this = this;
      let around = [];
      //console.log(arr, center);
      for (let i = 0; i < arr.length; i++) {
        let o = {};
        const element = arr[i];

        element.aroundLocations = element.path;

        let aroundLocations = [];
        for (let j = 0; j < element.path.length; j++) {
          const item = element.path[j];
          let obj = {};
          if (item instanceof Array) {
            obj = {
              lng: item[0],
              lat: item[1]
            };
          } else {
            obj = {
              lng: item.lng,
              lat: item.lat
            };
          }

          aroundLocations.push(obj);
        }
        o.aroundLocations = aroundLocations;

        around.push(o);
      }
      //console.log(around);
      if (lting == false) {
        var text = "是否新增?";
      } else {
        var text = "是否修改?";
      }
      if (around.length > 0) {
        _this
          .$confirm(text, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            let data = {};

            this.$http({
              url:
                "hsssystemadmin/v1/businessManagement/insertBusinessInformation",
              method: "POST",
              data: {
                businessArea: area,
                businessAreaCodeDto: arr[0].businessAreaCode,
                businessAreaName: arr[0].name,
                // groupId: _this.groupId,
                centralPointCoordinate: center,
                businessCoordinates: around,
                cityName: cityName ? cityName : "上海",
                cityCode: cityCode ? cityCode : "021"
              }
            }).then(res => {
              //console.log(res);
              _this.$message.success("添加成功");
              _this.reload();
            });
          })
          .catch(() => {
            _this.$message.success("已取消");
          });
      } else {
        this.$message.error("未划分区域");
        return;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  margin-bottom: 10px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
</style>
